package Demo4;

import Demo3.Base;

public class Derived extends Base {

    //定义属性
    public int a;//与父类同名
    public int b;
    public int c;

//    public Dirived(int a, int b, int c) {
//        this.a = a;
//        this.c = b;
//        this.b = c;
//    }

    //方法重载

    public void methodA() {
        System.out.println("Derived的methodA方法");
    }
    public void methodB() {
        System.out.println("Derived的methodB方法");
    }
    public void method(){
        methodA();//子类和父类重名，子类优先
        methodB();
        super.methodC();
    }

    //super关键字:在子类中调用父类成员或方法
    public void methodC(){
        a = 10;
        super.a = 100;
        b = 20 ;
        super.b = 200;
    }
    public void methodD(){
        super.methodD();
    }
    public void print(){
        System.out.println("Derived 的a : " + a);
        System.out.println("Base 的a : " + super.a);
        System.out.println("Derived 的b : " + b);
        System.out.println("Base 的b : " + super.b);

    }

    //构造
    public Derived(){
        super(10);
        System.out.println("Derived()");
    }
}

